<?php
require_once 'SqlHelper.class.php';
class EmpService {
	// 一个函数可以获取共有多少页
	function getPageCount($pageSize) {
		$sql = "select count(id) from emp";
		$sqlHelper = new SqlHelper ();
		
		$result = $sqlHelper->execute_sql ( $sql );
		// 这样我们就可以计算$pageCount
		if ($row = mysql_fetch_row($result )) {
			return ceil ( $row [0] / $pageSize );
		}
		// 释放资源
		mysql_free_result ( $result );
		$sqlHelper->close_connect ();
	}
	
	//一个函数可以获取应当现实的员工信息
	function getEmpListByPage($pageNow,$pageSize){
		
		$beginRow = ($pageNow-1)*$pageSize;
		
		$sql = "select id,name,grade,email,salary from emp limit $beginRow,$pageSize";

		$sqlHelper = new SqlHelper ();
		$result = $sqlHelper->execute_sql2($sql);
		
		return $result;
	}
	
	//第二种使用封装的方式分页方式
	function getPaging($paging){
		$sql1 = "select id,name,grade,email,salary from emp limit ".($paging->pageNow-1)*$paging->pageSize.",".$paging->pageSize;
		$sql2 = "select count(id) from emp";
		$sqlHelper = new SqlHelper ();
		
		 $sqlHelper->execute_sql_page($sql1, $sql2, $paging);
		 return $paging;
	}
}
?>